🤖 refactor: auto-cleanup#3291
Open
mux-bot[bot] wants to merge 4 commits into
Open
Conversation
dc0bbfe to
69d4d25
Compare
Both image_generate and image_edit duplicated the same "Adjust Settings > Experiments > Image Tools or request fewer images." setup hint literal when the requested image count exceeded the configured maxImagesPerCall. Hoist it next to the existing IMAGE_TOOL_PROVIDER_SETUP_HINT in imageArtifacts.ts so the guidance has a single source of truth, matching the pattern established by the prior auto-cleanup PR.
Move `urlAttributes`/`blockedSchemes` out of `sanitizeMermaidSvg` and into module-level constants (`SANITIZER_URL_ATTRIBUTES`, `SANITIZER_BLOCKED_URL_SCHEMES`). They are pure lookup data with no per-call dependency, so allocating them on every render of every Mermaid diagram was wasted work — these now allocate once per module load. Pure cleanup: identical contents, identical lookup semantics, no behavior change. The full Mermaid.test.tsx suite (including the recent sanitizer regression tests) still passes. --- _Generated with `mux` • Model: `anthropic:claude-opus-4-7` • Thinking: `xhigh` • Cost: `$`_ <!-- mux-attribution: model=anthropic:claude-opus-4-7 thinking=xhigh costs= -->
`summarizeToolPart` carried the AI SDK v5 `state` → lifecycle phase mapping inline as a nested ternary plus a multi-line comment listing the states. The ternary obscured the actual mapping (output-available and output-redacted both fold to "done") and made adding new states a multi-line edit. Hoist the mapping to a `TOOL_PART_PHASE_BY_STATE` record at module scope, keyed on the SDK state strings and typed as the literal phase union. The summarizer now does a single table lookup. States not in the table (e.g. `input-streaming`) still yield `null` and the bare `[tool <name>]` form, matching prior behavior exactly. Behavior-preserving: same input strings, same output bytes for every `state` value the prior code handled, and the same `null` fallthrough for everything else.
Three slash-command discovery surfaces (suggestions in ChatInput, ghost
hints in ChatInput, and CommandPalette) duplicated the same inline
lambda:
(experimentId) =>
resolveSlashCommandExperimentValue(experimentId, {
goals: goalsExperimentEnabled,
workspaceHeartbeats: workspaceHeartbeatsExperimentEnabled,
})
Add createSlashCommandExperimentResolver(snapshot) next to its sibling
resolver so each callsite only describes the experiment snapshot it
observes. The new helper returns the exact same closure each callsite
previously built inline, so behavior is byte-identical.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rolling, low-risk cleanup batch. Each run adds one extremely small,
behavior-preserving refactor picked from changes that have landed on
mainsince the last checkpoint.
Current diff against
main:src/browser/features/Messages/Mermaid.tsx— hoist the URL-attributeset and blocked-scheme list out of
sanitizeMermaidSvgintomodule-level constants (
SANITIZER_URL_ATTRIBUTES,SANITIZER_BLOCKED_URL_SCHEMES). They are pure lookup data with noper-call dependency, so allocating them on every Mermaid render was
wasted work; they now allocate once per module load. Identical
contents and identical lookup semantics — pure cleanup with no
behavior change.
src/node/services/agentStatusService.ts— hoist the AI SDK v5tool-part
state→ lifecycle phase mapping out ofsummarizeToolPartinto a module-level
TOOL_PART_PHASE_BY_STATErecord. The previousnested ternary obscured the actual mapping (
output-availableandoutput-redactedboth fold to"done") and made adding new states amulti-line edit. The summarizer now does a single table lookup; the
union-typed values document the two valid phases inline. States not
in the table (e.g.
input-streaming) still yieldnulland the bare[tool <name>]form, byte-for-byte identical to before.src/browser/utils/slashCommands/experimentVisibility.ts(+ twoconsumers) — add
createSlashCommandExperimentResolver(snapshot)alongside
resolveSlashCommandExperimentValue. Three slash-commanddiscovery surfaces (suggestions in
ChatInput, the ghost-hint call inChatInput, and theCommandPalettepalette query) had each inlinedthe same
(experimentId) => resolveSlashCommandExperimentValue(experimentId, { goals, workspaceHeartbeats })lambda. The new helper returns theexact same closure each callsite previously built inline, so the
isExperimentEnabledpredicate handed togetSlashCommandSuggestions/
getCommandGhostHintis behaviorally identical; only the wiringdetail (that resolution is parameterized by experiment id) moves into
the visibility module.
Validation
make static-check— eslint, tsgo (×2 configs), and prettier all greenlocally; the only red step is
fmt-shell-checkfailing becauseshfmtisn't installed in this environment (pre-existing env limitation, no
shell files touched by these changes).
bun test src/browser/features/Messages/Mermaid.test.tsx— 12/12pass, including the recent foreignObject/
<br>sanitizer regressiontests and the existing security-relevant cases (
<script>,on*handlers,javascript:hrefs).bun test src/node/services/agentStatusService.test.ts src/node/services/workspaceStatusGenerator.test.ts— 34/34 pass, including the tool-part lifecycle tests that key on the
running/donesuffixes the refactored lookup produces.bun test src/browser/utils/slashCommands/suggestions.test.ts src/browser/utils/slashCommands/ghostHint.test.ts— 27/27 pass, covering the experiment-gated visibility branches the
new helper feeds.
bun test src/browser/components/CommandPalette/CommandPalette.test.ts src/browser/features/ChatInput/CommandSuggestions.test.tsx— 16/16 pass, exercising the palette/suggestion rendering paths whose
isExperimentEnabledwiring changed.Risks
Negligible — all three changes are pure local hoisting / factory
extraction inside the same module. Allow/deny lists, the state→phase
mapping, and the experiment-resolver closure are byte-identical to the
inline versions; only their allocation site moved.
Process
Auto-cleanup checkpoint: 8f91862
Generated with
mux• Model:anthropic:claude-opus-4-7• Thinking:xhigh• Cost:$